# -*- coding: utf-8 -*-
# @Time    : 2024/11/10 14:31
# @Author  : CHNJX
# @File    : base.py
# @Desc    : 单元测试基类

import pytest
from app import create_app
from app.extensions import db

class TestBase:
    @pytest.fixture
    def app(self):
        """创建测试应用"""
        app = create_app('testing')
        return app

    @pytest.fixture
    def client(self, app):
        """创建测试客户端"""
        return app.test_client()

    @pytest.fixture(autouse=True)
    def setup_database(self, app):
        """设置测试数据库"""
        with app.app_context():
            db.create_all()
            yield
            db.session.remove()
            db.drop_all()
